package com.qingyun.modular.dengji.controller;

import com.github.pagehelper.Page;
import com.qingyun.common.annotion.DataSource;
import com.qingyun.common.constant.Const;
import com.qingyun.common.constant.DSEnum;
import com.qingyun.common.constant.factory.PageFactory;
import com.qingyun.common.controller.BaseController;
import com.qingyun.core.shiro.ShiroKit;
import com.qingyun.modular.model.Orders;
import com.qingyun.modular.order.service.IOrdersService;
import com.qingyun.modular.order.vo.OrdersVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * 分销商等级控制器
 */
@Controller
@RequestMapping("/dengjilist")
public class DengJiController extends BaseController {
    @Autowired
    IOrdersService orderService;

    private String prefix = "/dengji/";

    /**
     * 跳转到订单列表首页
     */
    @RequestMapping("")
    public String index(Model model) {
        return prefix + "/dengji.html";
    }

    /**
     * 分页获取订单列表
     * @param id 订单id
     * @param userId 分销商id
     * @param beginTime 订单开始时间
     * @param endTime 订单结束时间
     * @return
     */
    @RequestMapping(value = "/list")
    @DataSource(name = DSEnum.DATA_SOURCE_BIZ)//切换数据源
    @ResponseBody
    public Object list(String id,String userId,String beginTime,String endTime) {
        //分页对象信息封装
        Page page = new PageFactory<Orders>().defaultPage();
        //查询
        List<OrdersVo> list = orderService.selectList(id, userId, beginTime, endTime);
        long total = page.getTotal();
        //返回参数
        return super.packForBT(list,total);
    }

    /**
     * 跳转到添加页面
     */
    @RequestMapping("/dengji_add")
    public String disProfiParamAdd(Model model) {
        return prefix + "dengji_add.html";
    }

    /**
     * 新增
     */
    @RequestMapping(value = "/add")
    @DataSource(name = DSEnum.DATA_SOURCE_BIZ)//切换数据源
    @ResponseBody
    public Object add(Orders orders) {
        String account= ShiroKit.getUser().getAccount();
        if(!ShiroKit.hasRole(Const.ADMIN_NAME)){
            //param.setDisPlatformId(account);
        }
//        param.setIdentityType(IdentityStatus.USER_STATUS.getStatus());
//        disProfiParamService.save(param);
        return SUCCESS_TIP;
    }
}
